package com.lsa.letcode.the125.validPalindrome;

public class Solution {
    public boolean isPalindrome(String s) {
    	if (s.isEmpty()) {
    		return true;
    	}
        int i = 0;
        int j = s.length() - 1;

        while(i < j) {
        	while( i < j && !isAlfanumeric(s.charAt(i))) {
        		i++;
        	}
        	
        	while( i < j && !isAlfanumeric(s.charAt(j))) {
        		j--;
        	}
        	
        	char c1 = Character.toUpperCase(s.charAt(i)) ;
            char c2 = Character.toUpperCase(s.charAt(j));
            if (c1 != c2) {
            	return false;
            }
            
            i++;
            j--;
        }
        
        return true;
    }
    
    private static boolean isAlfanumeric(char c){
    	return Character.isLetter(c) || Character.isDigit(c); 
    }
}